<?php 
if (isset($_GET['ACT']) && $_GET['ACT'] == "VCREQ") { ?> 
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"> 
  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" runat="server"> 
    <input type="hidden" name="ACT" value="VCREQ"> 
    <tr bgcolor="#CFCFCF"> 
      <td colspan="2"><span style="color: #FFFFFF;">Marcação de Férias </span>      </td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td>Início:</td> 
      <td><input name="TimeStart" type="text" onFocus="this.select();lcs(this)" 
	  onClick="event.cancelBubble=true;this.select();lcs(this)" 
	  value="<?php if (isset($_POST['TimeStart'])) {
	  print $_POST['TimeStart']; } ?>" size="14" /></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td width="20%">Fim:</td> 
      <td><input name="TimeEnd" type="text" onFocus="this.select();lcs(this)" 
	  onClick="event.cancelBubble=true;this.select();lcs(this)" 
	  value="<?php if (isset($_POST['TimeEnd'])) {
	  print $_POST['TimeEnd']; } ?>" size="14" /></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td valign="top">ObservaÇ&otilde;es<br> 
      (Opcional)</td> 
      <td><textarea name="Observations" cols="60" rows="2" id="Observations"></textarea></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td bgcolor="#E8E8E8">&nbsp;</td> 
      <td><input name="Save" type="submit" id="Save" value="Submeter"></td> 
    </tr> 
  </form> 
</table> 
<?php } elseif (isset($_GET['Event'])) { ?> 
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"> 
  <form action="?" method="post" runat="server"> 
    <input type="hidden" name="Ev" value="<?php echo $_GET['Ev'];?>"> 
    <tr bgcolor="#CFCFCF"> 
      <td colspan="2"><span style="color: #FFFFFF;">Detalhes do Evento</span></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td>Tipo:</td> 
      <td> <?php if (isset($_GET['Event']) && $_GET['Event'] == 'Comp') { print 'Compensa��o';} 
		  if (isset($_GET['Event']) && $_GET['Event'] == 'Delay') { print 'Atraso';} ?> 
    <tr bgcolor="#E8E8E8"></td> 
    <tr bgcolor="#E8E8E8"></tr> 
      <tr bgcolor="#E8E8E8"> 
      <td width="20%">Data:</td> 
      <td>&nbsp;</td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td valign="top">ObservaÇ&otilde;es<br> 
        (Opcional)</td> 
      <td><textarea name="Observations" cols="60" rows="2" id="Observations"></textarea></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td>&nbsp;</td> 
      <td><input name="Save" type="submit" id="Save" value="Submeter"></td> 
    </tr> 
  </form> 
</table> 
<?php } elseif (isset($_GET['ACT']) && $_GET['ACT'] == "HDREQ") { 
 form_pr('EventProperties',$_SERVER['PHP_SELF'],'','post'); ?> 
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"> 
 
    <input type="hidden" name="ACT" value="HDREQ"> 
    <tr bgcolor="#CFCFCF"> 
      <td colspan="2"><span style="color: #FFFFFF;">R</span><span style="color: #FFFFFF;">equerer dispensa</span></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td>Dia:</td> 
      <td><input name="Day" type="text" onFocus="this.select();lcs(this)" 
	  onClick="event.cancelBubble=true;this.select();lcs(this)" 
	  value="<?php if (isset($_POST['Day'])) {
	  print $_POST['Day']; } else { print "AAAAMMDD";} ?>" size="14" /></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td width="20%">Periodo:</td> 
      <td>Das
        <input name="HourStart" type="text" value="<?php if (isset($_POST['HourStart'])) {
	  print $_POST['HourStart']; } else { print "00:00:00";} ?>" size="14" /> 
        às
        <input name="HourEnd" type="text" value="<?php if (isset($_POST['HourEnd'])) {
	  print $_POST['HourEnd']; } else { print "00:00:00";} ?>" size="14" /></td> 
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td valign="top">Justificação:</td> 
      <td><select name="Motiv" id="Motiv">
	  <?php
	  $CMotivs = "SELECT * FROM htck_delaytypes";
	  $Motivs = $GLOBALS['CONN']->db_array($CMotivs);
	  for ($r = 1; $r <= $Motivs[0]; $r++) {
	  echo '<option value="'.$Motivs[$r]['ref'].'">'.$Motivs[$r]['name'].'</option>';
	  } ?>
      </select>        </td> 
    </tr>
    <tr bgcolor="#E8E8E8">
      <td valign="top">ObservaÇ&otilde;es<br>
      (Opcional) </td>
      <td><textarea name="Observations" cols="60" rows="2" id="Observations"></textarea></td>
    </tr> 
    <tr bgcolor="#E8E8E8"> 
      <td>&nbsp;</td> 
      <td><input name="Save" type="submit" id="Save" value="Submeter"></td> 
    </tr> 
</table> 
</form>
<?php } else { ?>
<table width="100%"  border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC"> 
  <form action="?Events" method="post" runat="server" name="Update" enctype="multipart/form-data"> 
    <tr>
      <td width="18%" bgcolor="#F2F2F2">Tipo</td>
      <td width="26%" bgcolor="#F2F2F2">Data</td>
      <td width="15%" bgcolor="#F2F2F2">Estado</td>
      <td width="42%" bgcolor="#F2F2F2">Motivo</td>
    </tr>
    <?php 
		$CEvents = "SELECT 
						c.name AS Status,
						a.Justification,
						DATE(a.TimeStart) AS TimeStart,
						DATE(a.TimeEnd) AS TimeEnd,
						a.ref,
						b.name AS Type
					 FROM timeclock_vacs AS a
					 INNER JOIN htck_status AS c ON c.StatRef = a.Status AND c.Type = 2
					 INNER JOIN htck_types AS b ON b.StatRef = a.Type AND b.Type = 1
					 WHERE a.RefUser = {$_SESSION['UtID']}
					 AND YEAR(a.Time) = {$ConsultTime[0]}
					 AND MONTH(a.Time) = {$ConsultTime[1]}";
		$Events = $GLOBALS['CONN']->db_array($CEvents); 
		for ($r = 1; $r <=$Events[0]; $r++) { ?> 
    <tr> 
      <td bgcolor="#FCFCFC"><?php echo $Events[$r]['Type'];?></td>
      <td bgcolor="#FCFCFC">De <?php echo $Events[$r]['TimeStart'];?> a <?php echo $Events[$r]['TimeEnd'];?></td> 
      <td bgcolor="#FCFCFC"><?php echo $Events[$r]['Status'];?></td>
      <td bgcolor="#FCFCFC"><?php echo $Events[$r]['Justification'];?></td> 
    </tr> 
    <?php }
		$CEvents = "SELECT 
						b.name,
						a.Status,
						a.delaylevel,
						a.delaytime,
						a.Justify AS Just,
						DATE(a.EventTime) AS EventDate,
						d.name AS Justify,
						c.name AS Type,
						a.File,
						a.ref
					FROM timeclock_delays AS a
					INNER JOIN htck_status AS b ON b.StatRef = a.Status AND b.Type = 1
					INNER JOIN htck_types AS c ON c.StatRef = a.RefType AND c.Type = 2
					LEFT OUTER JOIN htck_delaytypes d ON d.ref = a.Justify
					WHERE a.main_user_ref = {$_SESSION['UtID']}
					AND YEAR(EventTime) = {$ConsultTime[0]}
					AND MONTH(EventTime) = {$ConsultTime[1]}";
		$Events = $GLOBALS['CONN']->db_array($CEvents); 
		for ($r = 1; $r <=$Events[0]; $r++) {?> 
    <tr> 
      <td bgcolor="#FCFCFC"><?php echo $Events[$r]['Type'];?></td>
      <td bgcolor="#FCFCFC"> 
	  <?php echo $Events[$r]['EventDate'].', Tempo:'.date("H:i:s",$Events[$r]['delaytime']-3600);?> </td> 
      <td bgcolor="#FCFCFC"><?php echo $Events[$r]['name'];?></td>
      <td bgcolor="#FCFCFC">
	  <?php if ($Events[$r]['Justify'] != '') {
	  echo $Events[$r]['Justify'];
				  if ($Events[$r]['Status'] == 3 && $Events[$r]['File'] == null) { 
				  echo '<input name="EventRef" type="hidden" value="'.$Events[$r]['ref'].'">
						<input name="DocFILE" type="file" id="DocFILE"> (Ficheiro .doc ou .pdf) 
						<input name="Send" type="submit" value="Enviar">';
						}
		} else {
	echo $Events[$r]['Just'];
		} ?></td> 
    </tr> 
    <?php } ?> 
  </form> 
</table>
<?php } ?>